﻿using System.Web.Http;
using System.Configuration;
using Microsoft.Owin;
using Owin;
using System.Collections.Generic;
using Beginor.Owin.StaticFile;

[assembly: OwinStartup(typeof(ServerTcp.Startup))]

namespace ServerTcp
{
    /********************************************************************************
** 作者： 谢磊
** 创建时间：2018-11-7
** 修改人：谢磊
** 修改时间：2018-11-7
** 描述：
**    主要是提供外部访问dcm  的web版的启动配置类
* ************************************************************/
    public class Startup
    {
        public void Configuration(IAppBuilder appBuilder)
        {


            HttpConfiguration config = new HttpConfiguration();

            ////跨域配置
            //var allowOrigins = ConfigurationManager.AppSettings["cors_allowOrigins"];
            //var allowHeaders = ConfigurationManager.AppSettings["cors_allowHeaders"];
            //var allowMethods = ConfigurationManager.AppSettings["cors_allowMethods"];
            //config.EnableCors(new EnableCorsAttribute(allowOrigins, allowHeaders, allowMethods));

          
            WebApiConfig.Register(config);



            //静态文件托管
            appBuilder.Map("/Web", map =>
            {
                // 允许跨域
                //map.UseCors(CorsOptions.AllowAll);
                map.UseStaticFile(new StaticFileMiddlewareOptions
                {
                    RootDirectory = @".\Web",
                    DefaultFile = "index.html",
                    EnableETag = true,
                    EnableHtml5LocationMode = true,
                    MimeTypeProvider = new MimeTypeProvider(new Dictionary<string, string>
                    {
                        { ".html", "text/html" },
                        { ".htm", "text/html" },
                        { ".dtd", "text/xml" },
                        { ".xml", "text/xml" },
                        { ".ico", "image/x-icon" },
                        { ".css", "text/css" },
                        { ".js", "application/javascript" },
                        { ".json", "application/json" },
                        { ".jpg", "image/jpeg" },
                        { ".png", "image/png" },
                        { ".gif", "image/gif" },
                        { ".config", "text/xml" },
                        { ".woff2", "application/font-woff2"},
                        { ".eot", "application/vnd.ms-fontobject" },
                        { ".svg", "image/svg+xml" },
                        { ".woff", "font/x-woff" },
                        { ".txt", "text/plain" },
                        { ".log", "text/plain" }
                    })
                });
            });
            appBuilder.UseWebApi(config);
        }

    }
}
